/**
 * 初始化账单详情对话框
 */
var TMonthbalanceDetailInfoDlg = {
    id: "MMTable1",	//表格id
    table: null,
    tMonthbalanceDetailInfoData : {}
};
<!-- 收货 -->
TMonthbalanceDetailInfoDlg.initColumn = function () {
    return [
        {title: '单号', field: 'original_num', visible: true, align: 'center', valign: 'middle'},
        {title: '收货人', field: 'consignee', visible: true, align: 'center', valign: 'middle'},
        {title: '货物名称', field: 'goods_name', visible: true, align: 'center', valign: 'middle'},
        {title: '件数', field: 'goods_piece', visible: true, align: 'center', valign: 'middle'},
        {title: '提付(付)', field: 'tf', visible: true, align: 'center', valign: 'middle',templet: '#tf'},
        {title: '代收货款(付)', field: 'dshk', visible: true, align: 'center', valign: 'middle',templet: '#dshk'},
        {title: '中转费(收)', field: 'zz', visible: true, align: 'center', valign: 'middle',templet: '#zz'},
        {title: '送货费(收)', field: 'shf', visible: true, align: 'center', valign: 'middle',templet: '#shf'},
        {title: '搬运费(收)', field: 'byf', visible: true, align: 'center', valign: 'middle',templet: '#byf'},
        {title: '合计费用', field: 'total', visible: true, align: 'center', valign: 'middle' ,templet: '#total' }
    ];
};
TMonthbalanceDetailInfoDlg.initColumn4 = function () {
    return [
        {title: '单号', field: 'original_num', visible: true, align: 'center', valign: 'middle'},
        {title: '收货人', field: 'consignee', visible: true, align: 'center', valign: 'middle'},
        {title: '货物名称', field: 'goods_name', visible: true, align: 'center', valign: 'middle'},
        {title: '件数', field: 'goods_piece', visible: true, align: 'center', valign: 'middle'},
        {title: '提付(付)', field: 'payment', visible: true, align: 'center', valign: 'middle'},
        {title: '代收货款(付)', field: 'collection', visible: true, align: 'center', valign: 'middle'},
        {title: '中转费(付)', field: 'zz', visible: true, align: 'center', valign: 'middle'},
        {title: '送货费(付)', field: 'sh', visible: true, align: 'center', valign: 'middle'},
        {title: '搬运费(付)', field: 'ty', visible: true, align: 'center', valign: 'middle'},
        {title: '合计费用', field: 'remark', visible: true, align: 'center', valign: 'middle'}

    ];
};

TMonthbalanceDetailInfoDlg.initColumn3 = function () {
    return [
        {title: '单号', field: 'original_num', visible: true, align: 'center', valign: 'middle'},
        {title: '收货人', field: 'consignee', visible: true, align: 'center', valign: 'middle'},
        {title: '货物名称', field: 'goods_name', visible: true, align: 'center', valign: 'middle'},
        {title: '件数', field: 'goods_piece', visible: true, align: 'center', valign: 'middle'},
        {title: '提付(付)', field: 'payment', visible: true, align: 'center', valign: 'middle'},
        {title: '代收货款(付)', field: 'collection', visible: true, align: 'center', valign: 'middle'},
        {title: '送货费(收)', field: 'sh', visible: true, align: 'center', valign: 'middle'},
        {title: '仓储费(收)', field: 'cc', visible: true, align: 'center', valign: 'middle'},
        {title: '搬运费(收)', field: 'ty', visible: true, align: 'center', valign: 'middle'},
        {title: '车费(付)', field: 'cf', visible: true, align: 'center', valign: 'middle'},
        {title: '合计费用', field: 'remark', visible: true, align: 'center', valign: 'middle'}

    ];
};

TMonthbalanceDetailInfoDlg.initColumn2 = function () {
    return [
        {title: '单号', field: 'original_num', visible: true, align: 'center', valign: 'middle'},
        {title: '收货人', field: 'consignee', visible: true, align: 'center', valign: 'middle'},
        {title: '货物名称', field: 'goods_name', visible: true, align: 'center', valign: 'middle'},
        {title: '件数', field: 'goods_piece', visible: true, align: 'center', valign: 'middle'},
        {title: '提付(付)', field: 'payment', visible: true, align: 'center', valign: 'middle'},
        {title: '代收货款(付)', field: 'collection', visible: true, align: 'center', valign: 'middle'},
        {title: '仓储费(收)', field: 'cc', visible: true, align: 'center', valign: 'middle'},
        {title: '搬运费(收)', field: 'ty', visible: true, align: 'center', valign: 'middle'},
        {title: '合计费用', field: 'remark', visible: true, align: 'center', valign: 'middle'}

    ];
};

TMonthbalanceDetailInfoDlg.initColumn5 = function () {
    return [
        {type: 'checkbox', fixed: 'left'},
        {title: '账单号', field: 'id', visible: true, align: 'center', valign: 'middle'},
        {title: '来源', field: 'income', visible: true, align: 'center', valign: 'middle',
            templet: function (d) {
                if(d.income==1){
                    return "收货"
                }else if(d.income==2){
                    return "自提"
                }else if(d.income==3){
                    return "配送"
                }else if(d.income==4){
                    return "中转"
                }else if(d.income==5){
                    return "改单"
                }else if(d.income==6){
                    return "抹平"
                }else if(d.income==7){
                    return "转结"
                }else if(d.income==8){
                    return "新转结"
                }
                return ""

            }},
        {title: '账单状态', field: 'status', visible: true, align: 'center', valign: 'middle',
            templet: function (d) {
                if(d.status==0){
                    return "待结算"
                }
                return "已结算"

            }
        },
        {title: '车次号', field: 'incomeName', visible: true, align: 'center', valign: 'middle'},
        {title: '网点/收货人', field: 'traner', visible: true, align: 'center', valign: 'middle'},
        {title: '应收金额', field: 'money', visible: true, align: 'center', valign: 'middle'},
        {title: '账单日期', field: 'createtime', visible: true, align: 'center', valign: 'middle'},
        {title: '创建人员', field: 'name', visible: true, align: 'center', valign: 'middle'},
        {title: '制单员', field: 'dotId', visible: true, align: 'center', valign: 'middle'},
        {title: '备注', field: 'remark', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 清除数据
 */
TMonthbalanceDetailInfoDlg.clearData = function() {
    this.tMonthbalanceDetailInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
TMonthbalanceDetailInfoDlg.set = function(key, val) {
    this.tMonthbalanceDetailInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
TMonthbalanceDetailInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
TMonthbalanceDetailInfoDlg.close = function() {
    parent.layer.close(window.parent.TMonthbalanceDetail.layerIndex);
}

/**
 * 收集数据
 */
TMonthbalanceDetailInfoDlg.collectData = function() {
    this
    .set('ids')
    .set('cash')
    .set('weixin')
    .set('alipay')
    .set('bank')
    .set('ramark')
    .set('m1')
    .set('m2')
    .set('traner')
    .set('income',$('input:radio[name=income]:checked').val())

    ;
}

/**
 * 提交添加
 */
TMonthbalanceDetailInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/tMonthbalanceDetail/add", function(data){
        Feng.success("添加成功!");
        window.parent.TMonthbalanceDetail.table.refresh();
        TMonthbalanceDetailInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.tMonthbalanceDetailInfoData);
    ajax.start();
}

var mData=null;
TMonthbalanceDetailInfoDlg.collectSum = function(m) {
    if(m){
        mData=m;
    }
    var djs=0;//待结算
    var yjs=0;//已结算
    for(var i=0;i<mData.data.length;i++){
        if(mData.data[i].tf_jsqk==0){
            //提付结算情况 0已结算
            yjs+=parseFloat(mData.data[i].tf);
        }else{
            djs+=parseFloat(mData.data[i].tf);
        }
        if(mData.data[i].dshk_jsqk==0){//代收货款
            yjs+=parseFloat(mData.data[i].dshk);
        }else{
            djs+=parseFloat(mData.data[i].dshk);
        }
        if(mData.data[i].zz_jsqk==0){//中转费
            yjs+=parseFloat(mData.data[i].zz);
        }else{
            djs+=parseFloat(mData.data[i].zz);
        }
        if(mData.data[i].byf_jsqk==0){//搬运费
            yjs+=parseFloat(mData.data[i].byf);
        }else{
            djs+=parseFloat(mData.data[i].byf);
        }
        if(mData.data[i].shf_jsqk==0){//送货费
            yjs+=parseFloat(mData.data[i].shf);
        }else{
            djs+=parseFloat(mData.data[i].shf);
        }
    }
    $('#djs').html(djs);
    $('#yjs').html(yjs);

}

var aTable = null
var mTable = null;
$(function () {
    var flag=$('#flag').val();
    var defaultColunms =null;
    var sUl="/tMonthbalanceDetail/listDetail?flag="+$('#flag').val()+'&id='+$('#id').val();
    if(flag==1){//收货
        defaultColunms = TMonthbalanceDetailInfoDlg.initColumn();
    }else if(flag==2){
        defaultColunms = TMonthbalanceDetailInfoDlg.initColumn2();
    }else if(flag==3){
        defaultColunms = TMonthbalanceDetailInfoDlg.initColumn3();
    }else if(flag==4){
        defaultColunms = TMonthbalanceDetailInfoDlg.initColumn4();
    }else{
        defaultColunms = TMonthbalanceDetailInfoDlg.initColumn5();
        sUl="/tMonthbalanceDetail/listDetail?flag="+$('#flag').val()+'&id='+$('#bId').val();
    }
    aTable = new LYTable(TMonthbalanceDetailInfoDlg.id,sUl, defaultColunms);
    layui.use('table', function () {
        mTable = layui.table;
            TMonthbalanceDetailInfoDlg.table = aTable.initCallBack(mTable, TMonthbalanceDetailInfoDlg.collectSum);
    })


});
